//
//  MXZDPopupView.swift
//  d11
//
//  Created by peale_pro on 2019/7/18.
//  Copyright © 2019年 Tech_001. All rights reserved.
//

import UIKit
import MJRefresh
class MXZDPopupView: UIView,UITableViewDelegate,UITableViewDataSource {
    
    var imgName :String?
    var typeName:String?
    var requestPath: String?
    var index = 0
    var pageCount = 20
    var requestType: String?
    var typeAllName = "全平台"
    var dataDict: [String : [[String:Any]]] = [:]
    var startDateTextField: SelectionTextField!
    var endDateTextField: SelectionTextField!
    var typeTextField: SelectionTextField!
    
    var keysArray : [String]? = [String]()
    
    var gpData = [String:String]()
    var selectedGpType: NSString = "0"
    var selectedGpIndex: Int = 0
    let  reuseIdentifierHeadID : NSString = "TransferHeaderView"
    let  reuseIdentifierID : NSString = "DividendCasBackRecordCell"
    let  reuseIdentifierID2 : NSString = "BettingRecordCell"
    var _loadView: UIView?
    var  currentVC: UIViewController?
    var isHorizontalScreen :Bool = false
    var popScreenWidth : CGFloat = kScreenWidth
    var ipadAddHeight :CGFloat = 100
    lazy var tableView:UITableView = {
        var topHeight = 0
        let table = UITableView(frame:CGRect(x: 0, y: 0, width: self.popScreenWidth-20, height:305+self.ipadAddHeight), style:UITableView.Style.plain)
        table.dataSource = self
        table.delegate = self
        //table.layoutMargins = UIEdgeInsets.zero
        table.separatorStyle = .none
        table.backgroundColor  = UIColor.white
        table.showsVerticalScrollIndicator = false
        table.tableFooterView = UIView.init()
        table.separatorStyle = .none
        table.autoresizingMask = [.flexibleWidth,.flexibleHeight]
        table.estimatedRowHeight = 0
        table.estimatedSectionHeaderHeight = 0
        table.estimatedSectionFooterHeight = 0
        if #available(iOS 11.0, *) {
            table.contentInsetAdjustmentBehavior = .never

        }
        table.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {
            self.pullToRefresh()
        })
        return table
    }()
    
    lazy var noDataLabel : UILabel = {
        let noLabel = UILabel.init(frame: CGRect(x: 0, y: 170, width: self.tableView.width, height:40))
        // noLabel.center = self.tableView.center
        noLabel.text =  "暂无记录"
        noLabel.isHidden = true
        noLabel.textAlignment = .center
        noLabel.textColor = HexRGBAlpha(0x666666,1)
        noLabel.font = UIFont.systemFont(ofSize: 15)
        self.tableView.addSubview(noLabel)
        return noLabel
    }()
    
    //刷新数据
    func pullToRefresh() -> Void {
        self.getRecordList()
    }
    
    //获取分类列表
    func codeList() -> Void {
        RequestHelper.get(atPath: "/walletm/getCodeList", withCompletion: { data in
            let responseArray = try JSONSerialization.jsonObject(with: data, options: []) as! [String: String]
            print("分类类别\(responseArray)")
            DispatchQueue.main.async {
                self.gpData.removeAll()
                self.gpData = responseArray
                var typeNames = Array(self.gpData.values)
                typeNames.insert(self.typeAllName, at: 0)
                self.gpData["0"] = self.typeAllName
                self.typeTextField.isEnabled = true
                self.typeTextField.showSingleColPicker("选择平台类型", data: typeNames, defaultSelectedIndex:self.selectedGpIndex, autoSetSelectedText: false) {(textField, selectedIndex, selectedValue) in
                    for (key, value) in self.gpData {
                        print("\(key) : \(value)")
                        if selectedValue == value {
                            self.selectedGpIndex = selectedIndex
                            self.selectedGpType = key as NSString
                            self.typeTextField.text = selectedValue
                            self.index = 0
                            self.dataDict.removeAll()
                            self.keysArray?.removeAll()
                            self.getRecordList()
                            break
                        }
                    }
                    
                }
            }
            
        }, withError: { error in
            print(error)
            DispatchQueue.main.async {
                UIHelper.alertSimpleMessage(about: "无法取得平台列表,\(getErrorString())", withDescription: "", in: self.currentVC!)
                self.gpData.removeAll()
            }
        })
    }
    
    convenience init(imgName:String,typeName:String,vc:UIViewController,isHorizontalScreen:Bool) {
        self.init(frame: UIScreen.main.bounds)
        let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
        self.backgroundColor = UIColor.clear
        window.addSubview(self)
        self.imgName = imgName
        self.typeName = typeName
        self.currentVC = vc
        self.requestPath = "/walletm/history"
        self.requestType = BonusType.betting
        self.isHorizontalScreen = isHorizontalScreen
        self.popScreenWidth = kScreenWidth
        if kIsIpad == true{
            if kScreenWidth < 415+100{
                self.popScreenWidth = kScreenWidth
                self.ipadAddHeight = kScreenWidth-415
            }else{
                self.popScreenWidth = 415+100
            }
            
        }else{
            self.popScreenWidth = kScreenWidth
            self.ipadAddHeight = 0
        }
        //感知设备方向 - 开启监听设备方向
        UIDevice.current.beginGeneratingDeviceOrientationNotifications()
        //添加通知，监听设备方向改变
        NotificationCenter.default.addObserver(self, selector: #selector(MXZDPopupView.receivedRotation), name: UIDevice.orientationDidChangeNotification, object: nil)
        self.initUI()
    }
    
    @objc func receivedRotation(){
        self.closePageView()
    }
    @objc func closePageView() -> Void {
        self.removeFromSuperview()
    }
    func initUI(){
        let bgView :UIView  = UIView.init()
        bgView.backgroundColor = RGBAlpa(0,0,0,0.4)
        bgView.tag = 3001
        bgView.isUserInteractionEnabled = true
        bgView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(closePageView)))
        let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
        ////        let effecView = UIHelper.showBlurEffect(isClick:true)
        ////       window.addSubview(effecView)
        self.addSubview(bgView)
        bgView.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
            make.top.equalToSuperview()
            make.bottom.equalToSuperview()
        }
        
        let whiteView = UIView.init()
        whiteView.backgroundColor = HexRGBAlpha(0xf6f8fa, 1)
        whiteView.layer.cornerRadius = 5;
        whiteView.layer.masksToBounds = true
        self.addSubview(whiteView)
        whiteView.snp.makeConstraints { (make) in
            if kIsIpad == true{
                make.width.equalTo(self.popScreenWidth-20)
            }else{
                if self.isHorizontalScreen == true{
                    make.width.equalTo(self.snp.height).offset(-20)
                }else{
                    make.width.equalToSuperview().offset(-20)
                }
            }
            if kScreenWidth <= 320 && self.isHorizontalScreen == true{
                make.height.equalTo(300)
            }else{
                make.height.equalTo(350+self.ipadAddHeight)
            }
            
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview()
        }
        
        let iconImageView = UIImageView.init()
        iconImageView.image = UIImage.init(named: self.imgName ?? "")
        whiteView.addSubview(iconImageView)
        iconImageView.snp.makeConstraints{(make) in
            make.width.equalTo(35)
            make.height.equalTo(35)
            make.top.equalToSuperview().offset(5)
            make.left.equalToSuperview().offset(15)
        }
        
        
        
        let closeLabel = UILabel.init()
        closeLabel.textColor = HexRGBAlpha(0x747474, 1)
        closeLabel.font = UIFont.systemFont(ofSize: 20)
        closeLabel.text =  "X"
        closeLabel.textAlignment = .right
        closeLabel.isUserInteractionEnabled = true
        closeLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(closePageView)))
        whiteView.addSubview(closeLabel)
        closeLabel.snp.makeConstraints{(make) in
            make.right.equalToSuperview().offset(-10)
            make.height.equalTo(25)
            make.width.equalTo(40)
            make.top.equalToSuperview().offset(10)
        }
        
        let nameLabel = UILabel.init()
        nameLabel.textColor = HexRGBAlpha(0x747474, 1)
        nameLabel.font = UIFont.systemFont(ofSize: 15)
        nameLabel.text =  self.typeName
        nameLabel.textAlignment = .left
        whiteView.addSubview(nameLabel)
        nameLabel.snp.makeConstraints{(make) in
            make.left.equalTo(iconImageView.snp.right).offset(15)
            make.right.equalTo(closeLabel.snp.left).offset(15)
            make.height.equalTo(25)
            make.top.equalToSuperview().offset(10)
        }
        whiteView.addSubview(self.tableView)
        self.tableView.snp.makeConstraints{(make) in
            make.top.equalTo(nameLabel.snp.bottom).offset(10)
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.bottom.equalToSuperview().offset(-10)
        }
        self.gpData.removeAll()
        self.gpData = ["0":self.typeAllName]
        self.initHeadView()
        self.codeList()
        self.dataDict.removeAll()
        self.getRecordList()
        if self.typeTextField != nil{
            self.typeTextField.addTarget(self, action: #selector(begainSelect), for: .editingDidBegin)
        }
    }
    
    @objc func begainSelect() {
        ToolHelper.statisticsPage(pageName: "我的-红利返水-选择平台")
    }
    
    //初始化顶部视图
    func initHeadView() -> Void {
        //15 37.5 15 40 15
        //15 + 40
        var topHeight = 0
        if requestType == BonusType.betting{
            topHeight = 50
        }
        let headBgView : UIView =  UIView.init()
        headBgView.backgroundColor = UIColor.white
      //  self.view.addSubview(headBgView)
        self.tableView.tableHeaderView = headBgView
        headBgView.snp.makeConstraints{(make) in
            make.top.equalToSuperview()
            make.width.equalToSuperview()
            make.height.equalTo(topHeight+130)
            make.left.equalToSuperview()
            
        }
        
        if requestType == BonusType.betting{
            //顶部 标题：选择平台 按钮：所有平台
            let topLabel : UILabel =  UILabel.init()
            topLabel.textAlignment = .left
            topLabel.text = "选择平台:"
            topLabel.textColor = HexRGBAlpha(0xA0A1A2,1)
            headBgView.addSubview(topLabel)
            topLabel.snp.makeConstraints{(make) in
                make.width.equalTo(75)
                make.top.equalToSuperview().offset(20)
                make.height.equalTo(30)
                make.left.equalToSuperview().offset(25)
            }
            
            
            let arrowImageView  = UIImageView.init()
            arrowImageView.image = imageNamed("icon_common_arrow")
            headBgView.addSubview(arrowImageView)
            arrowImageView.snp.makeConstraints{(make) in
                make.top.equalToSuperview().offset(28.5)
                make.width.equalTo(7)
                make.height.equalTo(13)
                make.right.equalTo(-25)
            }
            
            self.typeTextField = SelectionTextField()
            self.typeTextField.placeholder = self.typeAllName
            self.typeTextField.text = self.typeAllName
            self.typeTextField.isEnabled = false
            self.typeTextField.textAlignment = .right
            
            typeTextField.showSingleColPicker("选择平台类型", data: Array(self.gpData.values), defaultSelectedIndex: 0, autoSetSelectedText: false) {(textField, selectedIndex, selectedValue) in
                
            }
            headBgView.addSubview(self.typeTextField)
            typeTextField.snp.makeConstraints{(make) in
                make.top.equalToSuperview().offset(20)
                make.width.equalTo(110)
                make.right.equalTo(arrowImageView.snp.left).offset(-15)
                make.height.equalTo(30)
            }
        }
        
        
        let centerLabel : UILabel =  UILabel.init()
        centerLabel.textAlignment = .center
        centerLabel.text = "至"
        centerLabel.textColor = HexRGBAlpha(0xA0A1A2,1)
        headBgView.addSubview(centerLabel)
        centerLabel.snp.makeConstraints{(make) in
            make.top.equalToSuperview().offset(15+topHeight)
            make.width.equalTo(44)
            make.centerX.equalToSuperview()
            make.height.equalTo(37.5)
        }
        let leftView :UIView = UIView.init()
        leftView.backgroundColor = HexRGBAlpha(0xf1f2f3,1)
        headBgView.addSubview(leftView)
        leftView.snp.makeConstraints{(make) in
            make.top.equalToSuperview().offset(15+topHeight)
            make.width.equalTo(0.7)
            make.right.equalTo(centerLabel.snp.left)
            make.height.equalTo(37.5)
        }
        
        let rightView :UIView = UIView.init()
        rightView.backgroundColor = HexRGBAlpha(0xf1f2f3,1)
        headBgView.addSubview(rightView)
        rightView.snp.makeConstraints{(make) in
            make.top.equalToSuperview().offset(15+topHeight)
            make.width.equalTo(0.7)
            make.right.equalTo(centerLabel.snp.right)
            make.height.equalTo(37.5)
        }
        
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd"
        
        self.startDateTextField = SelectionTextField()
        let cdate = Date()
        let startDate = cdate.adjust(.day, offset: -14)
        
        let dateStr = formatter.string(from: startDate)
        self.startDateTextField.placeholder = "开始日期"
        self.startDateTextField.text = dateStr
        self.startDateTextField.textAlignment = .center
        var dateStyle = DatePickerSetting()
        dateStyle.dateMode = .date
        dateStyle.date = cdate
        dateStyle.maximumDate = cdate
        headBgView.addSubview(self.startDateTextField)
        self.startDateTextField.snp.makeConstraints{(make) in
            make.top.equalToSuperview().offset(15+topHeight)
            make.width.equalTo(110)
            make.right.equalTo(leftView.snp.left)
            make.height.equalTo(37.5)
        }
        
        
        let formatter2 = DateFormatter()
        formatter2.dateFormat = "yyyy-MM-dd"
        self.endDateTextField = SelectionTextField()
        self.endDateTextField.placeholder = "结束日期"
        self.endDateTextField.text = formatter.string(from: cdate)
        self.endDateTextField.textAlignment = .center
        var dateStyle2 = DatePickerSetting()
        dateStyle2.dateMode = .date
        dateStyle2.date = cdate
        dateStyle2.maximumDate = cdate
        //   dateStyle2.minimumDate = startDate
        
        self.startDateTextField.showDatePicker("开始日期", datePickerSetting: dateStyle, autoSetSelectedText: false) { (textField, selectedDate) in
            let string = formatter.string(from: selectedDate)
            let sDate = formatter.date(from:string)
            let eDate = formatter.date(from:self.endDateTextField.text!)
            let components = NSCalendar.current.dateComponents([.day], from: sDate!, to: eDate!)
            print("时间\(components)")
            if  components.day != nil && components.day!+1 > 15 {
                UIHelper.alertSimpleMessage(about: "", withDescription: "查询范围超过15天!", in: self.currentVC!)
            }else{
                textField.text = string
                self.startDateTextField.selectDate = selectedDate
            }
            //   self.endDateTextField.minmumDate = selectedDate
        }
        
        
        
        self.endDateTextField.showDatePicker("结束日期", datePickerSetting: dateStyle2, autoSetSelectedText: false) { (textField, selectedDate) in
            let string = formatter.string(from: selectedDate)
            let tempStartDate = formatter.date(from: self.startDateTextField.text!)
            if selectedDate.compare(tempStartDate!) == .orderedAscending
            {
                print("<")
                UIHelper.alertSimpleMessage(about: "", withDescription: "结束日期不能小于开始日期!", in: self.currentVC!)
                //  self.startDateTextField.text = string
            }else
            {
                let formatter = DateFormatter()
                formatter.dateFormat = "yyyy-MM-dd"
                let eDate = formatter.date(from:string)
                let sDate = formatter.date(from:self.startDateTextField.text!)
                let components = NSCalendar.current.dateComponents([.day], from: sDate!, to: eDate!)
                print("时间\(components)")
                if components.day != nil && components.day!+1 > 15 {
                    UIHelper.alertSimpleMessage(about: "", withDescription: "查询范围超过15天!", in: self.currentVC!)
                }else{
                    textField.text = string
                    self.endDateTextField.selectDate = selectedDate
                }
                //    self.startDateTextField.maxmumDate = selectedDate
            }
        }
        headBgView.addSubview(self.endDateTextField)
        self.endDateTextField.snp.makeConstraints{(make) in
            make.top.equalToSuperview().offset(15+topHeight)
            make.width.equalTo(110)
            make.left.equalTo(rightView.snp.right)
            make.height.equalTo(37.5)
        }
        
        
        let searchBtn : UIButton  = UIButton.init(type: .custom)
        if BonusType.dividendCasBack == self.requestType
        {
            searchBtn.setTitle("查询", for: .normal)
        }else{
            searchBtn.setTitle("搜索", for: .normal)
        }
        
        let layerGradient = CAGradientLayer()
        layerGradient.colors = [
            UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
            UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
        ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: kScreenWidth-100, height: 40)
        searchBtn.layer.addSublayer(layerGradient)
        searchBtn.layer.cornerRadius = 5;
        searchBtn.layer.masksToBounds = true
        searchBtn.addTarget(self, action: #selector(self.actionToSearch), for: .touchUpInside)
        headBgView.addSubview(searchBtn)
        searchBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-100)
            make.height.equalTo(40)
            make.centerX.equalToSuperview()
            make.top.equalTo(centerLabel.snp.bottom).offset(15)
        }
    }
    
    //选择平台 : 50  top:20 height:30
    //搜索
    @objc func actionToSearch() -> Void {
        self.index = 0
        self.dataDict.removeAll()
        self.keysArray?.removeAll()
        if self.requestType != BonusType.betting{
            self._loadView = UIHelper.initLoadView2(withMessage:"读取中...")
            self.addSubview(self._loadView!)
            self.tableView.mj_footer?.resetNoMoreData()
        }
        self.getRecordList()
        if requestType == BonusType.dividendCasBack{
            ToolHelper.statisticsPage(pageName: "首页-最新红利-查询")
        }else if requestType == BonusType.betting{
            ToolHelper.statisticsPage(pageName: "我的-我的投注-投注查询")
        }
    }
    //获取数据
    func getRecordList() -> Void {
        var params =  [
            "start": self.startDateTextField.text! + " 00:00:00",
            "end": self.endDateTextField.text! + " 23:59:59",
            ]
        if BonusType.dividendCasBack == self.requestType{
            params["offset"] = String(self.index)
            params["pageCount"] = String(self.pageCount)
        }else
        {
            self._loadView = UIHelper.initLoadView2(withMessage:"读取中...")
            self.addSubview(self._loadView!)
        }
        params["gpId"] = self.selectedGpType as String
        let paramString = RequestHelper.convertGetParams(params)
        self.noDataLabel.isHidden = true
        RequestHelper.get(atPath: self.requestPath! + "?\(paramString)", withCompletion: { data in
            do{
                
                let dataArray = try JSONSerialization.jsonObject(with: data, options: []) as! [[String: Any]]
                print("记录:\(dataArray)")
                let numToAdd = dataArray.count
                DispatchQueue.main.async {
                    self._loadView?.removeFromSuperview()
                    self.index += numToAdd
                    for(_,value) in dataArray.enumerated(){
                        //   print("元素的索引是：\(index),元素值是：\(value)")
                        var tempValue = value;
                        var datenName = "bettime"
                        let datestr  =  tempValue[datenName] ?? ""
                        let datetime = Date(fromString:datestr as! String, format: .custom("yyyy-MM-dd HH:mm:ss"))
                        let yearstr = datetime?.toString(format: .isoYear)
                        let monthDayStr = datetime?.toString(format: .custom("MM-dd"))
                        let timeStr = datetime?.toString(format: .custom("HH:mm:ss"))
                        tempValue["monthDay"] = monthDayStr
                        tempValue["showTime"] = timeStr
                        var array = self.dataDict[yearstr!]
                        if array == nil { //不存在 当前年份的数组则创建
                            var tempArr = [[String:Any]]() // 创建数组
                            tempArr.append(tempValue ) //添加条目
                            self.dataDict[yearstr!] = tempArr
                        }else
                        {
                            array?.append(tempValue)
                            self.dataDict[yearstr!] = array
                        }
                        //     }
                    }
                    //排序
                    self.keysArray = Array(self.dataDict.keys).sorted(by: { (num1 :String, num2:String) -> Bool in
                        return num1 > num2
                    })
                    //                    print(self.keysArray as Any)
                    self.tableView.reloadData()
                  //  if self.requestType != BonusType.betting{
                        if numToAdd<self.pageCount{
                            if numToAdd <= 0&&self.index == 0{
                                self.noDataLabel.isHidden = false
                                //     UIHelper.alertSimpleMessage(about: "当前时间内没有任何记录，请更改条件", withDescription: "", in: self)
                                if self.tableView.mj_footer?.isRefreshing == true{
                                    self.tableView.mj_footer?.endRefreshing()
                                }
                            }else
                            {
                                self.tableView.mj_footer?.endRefreshingWithNoMoreData()
                            }
                        }else
                        {
                            if self.tableView.mj_footer?.isRefreshing == true{
                                self.tableView.mj_footer?.endRefreshing()
                            }
                        }
//                    }else{
//                        if numToAdd <= 0{
//                            self.noDataLabel.isHidden = false
//                            // UIHelper.alertSimpleMessage(about: "当前时间内没有任何记录，请更改条件", withDescription: "", in: self)
//                        }
//                    }
                    
                }
                
            } catch {
                print(String(data: data, encoding: .utf8) as Any)
                DispatchQueue.main.async {
                    self._loadView?.removeFromSuperview()
                    if self.requestType != BonusType.betting{
                        if self.tableView.mj_footer?.isRefreshing == true{
                            self.tableView.mj_footer?.endRefreshing()
                        }
                    }
                    
                    UIHelper.alertSimpleMessage(about: "", withDescription: "取得资料时发生异常,\(getErrorString())", in: self.currentVC!)
                }
            }
            
        }, withError: { error in
            print(error)
            DispatchQueue.main.async {
                self._loadView?.removeFromSuperview()
                if self.requestType != BonusType.betting{
                    if self.tableView.mj_footer?.isRefreshing == true{
                        self.tableView.mj_footer?.endRefreshing()
                    }
                }
                UIHelper.alertSimpleMessage(about: "", withDescription: "取得资料时发生异常", in: self.currentVC!)
            }
        })
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return (self.keysArray?.count)!
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        let keyYear = self.keysArray![section]
        let array = self.dataDict[keyYear]
        return array!.count
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 95
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        var headerView : TransferHeaderView? =  (tableView.dequeueReusableHeaderFooterView(withIdentifier: reuseIdentifierHeadID as String) as? TransferHeaderView)
        if headerView == nil {
            headerView = TransferHeaderView(reuseIdentifier: reuseIdentifierHeadID as String)
        }
        let title : String =  self.keysArray![section]
        headerView?.setData(title: title)
        return  headerView
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 30
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell :BettingRecordCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifierID2 as String) as? BettingRecordCell
        if cell == nil {
            cell =  BettingRecordCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: reuseIdentifierID2 as String)
        }
        let keyYear = self.keysArray![indexPath.section]
        let array = self.dataDict[keyYear]
        var isShowMonthDay : Bool = true
        let currentDict  = array![indexPath.row]
        if indexPath.row != 0 {
            let lastDict  = array![indexPath.row-1]
            if currentDict["monthDay"]  as? String ==  lastDict["monthDay"]  as? String{
                isShowMonthDay = false
            }
        }
        cell?.setData(dict: currentDict, isShowMonthDay: isShowMonthDay)
        return cell!
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let keyYear = self.keysArray![indexPath.section]
        let array = self.dataDict[keyYear]
        let currentDict  = array![indexPath.row]
        PopWindowHelper.showBettingRecordPopView(title: (currentDict["gp_type"] as? NSString)!, msg: currentDict)
        
    }
}
